
require("../../assets/css/index.less")
require("../../assets/iconfont/iconfont.css")
require("./login.less")

const axios = require("axios")

function $(select){
    return document.querySelector(select)
}
const request = require("../../lib/requst")


$(".log_bt").addEventListener("click",function(){
    request.post("/api/user/login",{
    account : `${$(".user").value}`,
    password:  `${$(".pwd").value}`
}).then(res=>{
    if(res.data.errno === 0 ){
        $(".small_tip").style.display = "flex";
        $(".success").textContent ="登录成功",
        $(".icon_x").classList.remove("icon-cuowu");
        $(".icon_x").classList.add("icon-zhengque")
        localStorage.setItem("token","Bearer " +res.data.data.token) //Bearer后面有空格
        setTimeout(() => {
            location.href = "./home.html";
        }, 2000);
    }else{
        $(".small_tip").style.display = "flex";
        $(".success").textContent ="登录失败",
        $(".icon_x").classList.remove("icon-zhengque");
        $(".icon_x").classList.add("icon-cuowu")
        setTimeout(() => {
            $(".small_tip").style.display = "none";
        }, 2000);
    }
})
})
